package gdconf

import (
	"server_cluster/common/logger"
)

// 活动参数配置表

const (
	ActivityParamTypeSignInDailyReward        = 1 // 签到活动每日奖励
	ActivityParamTypeSignInTotalReward        = 2 // 签到活动累计奖励
	ActivityParamTypeSignInDailyRoutineReward = 3 // 签到活动每日常规奖励
	ActivityParamTypeZpReward                 = 4 // 转盘奖励
	ActivityParamTypeZpBdReward               = 5 // 转盘保底奖励
	ActivityParamTypeZpTask                   = 6 // 转盘任务
	ActivityParamTypeZpProbRuleId             = 7 // 转盘概率公式id
	ActivityParamTypeZpOnceCostItem           = 8 // 转盘单抽消耗道具
	ActivityParamTypeZpBigReward              = 9 // 转盘本期大奖
)

type ActivityParamConfig struct {
	Id              int32  `csv:"Id" gorm:"primary_key;autoIncrement:false"` // id
	ActivityParamId int32  `csv:"GoalId,omitempty"`                          // 活动参数id
	Type            int32  `csv:"Type,omitempty"`                            // 活动参数类型
	Param1          int32  `csv:"Param1,omitempty"`                          // 参数1
	Param2          int32  `csv:"Param2,omitempty"`                          // 参数2
	Param3          int32  `csv:"Param3,omitempty"`                          // 参数3
	Param4          int32  `csv:"Param4,omitempty"`                          // 参数4
	Param5          int32  `csv:"Param5,omitempty"`                          // 参数5
	ComplexParam    string `csv:"Param101,omitempty"`                        // 复杂参数
}

func (a *ActivityParamConfig) TableName() string {
	return "config_activity_param"
}

func (g *GameDataConfig) saveActivityParamConfig() {
	saveTableToDb[ActivityParamConfig](g.Db, readTable[ActivityParamConfig](g.CsvPathPrefix+"PayGoal.csv"))
}

func (g *GameDataConfig) loadActivityParamConfig() {
	g.GameDataMaps.ActivityParamConfigMap = make(map[int32]*ActivityParamConfig)
	for _, activityParamConfig := range loadTableFromDb[ActivityParamConfig](g.Db) {
		g.GameDataMaps.ActivityParamConfigMap[activityParamConfig.Id] = activityParamConfig
	}
	logger.Info("ActivityParamConfig Count: %v", len(g.GameDataMaps.ActivityParamConfigMap))
}

func GetActivityParamConfig(id int32) *ActivityParamConfig {
	value, exist := CONF.GameDataMaps.ActivityParamConfigMap[id]
	if !exist {
		logger.Error("[ConfigNotFound] ActivityParamConfig, id: %v", id)
		return nil
	}
	return value
}

func GetActivityParamConfigMap() map[int32]*ActivityParamConfig {
	return CONF.GameDataMaps.ActivityParamConfigMap
}

func GetActivityParamConfigByParamId(activityParamId int32) []*ActivityParamConfig {
	ret := make([]*ActivityParamConfig, 0)
	for _, activityParamConfig := range CONF.GameDataMaps.ActivityParamConfigMap {
		if activityParamConfig.ActivityParamId != activityParamId {
			continue
		}
		ret = append(ret, activityParamConfig)
	}
	return ret
}
